from rest_framework import serializers
from baykeadmin.config.default import UPLOAD_IMAGE_SIZE


class UploadImageSerializer(serializers.Serializer):
    """ 上传图片序列化器 """
    image = serializers.ImageField(label="图片", required=True)

    def validate(self, attrs):
        if attrs['image'].size > UPLOAD_IMAGE_SIZE:
            raise serializers.ValidationError("图片大小不能超过2M")
        return super().validate(attrs)